/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * TToan.java
 *
 * Created on Jan 29, 2013, 5:00:34 PM
 */
package CLIENT;

import BLL.ThanhToanBLL;
import DTO.Thanhtoan;
import java.sql.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author Tieu Thien
 */
public class TToan extends javax.swing.JFrame {
      CSKhachHang parentFrame;
      private int giap;
      Date ngaytt;
      int tienTT;
       
    /** Creates new form TToan */
    public TToan(CSKhachHang parent) {
        initComponents();
        parentFrame = parent; 
        Date ngay = new Date(System.currentTimeMillis());
        this.txtNgay.setText(ngay+"");
        this.ngaytt=ngay;
    }

           
    public void setCMT(String cmt){
     this.txtCMT.setText(cmt);
    }
     public void setMaphong(String ma){
     this.txtma.setText(ma);
    }
    public void setKieu(String kieuTT){
    this.txtDonvi.setText(kieuTT);
    }
    public void setGia(int gia){
    String txtGia = String.valueOf(gia);
    this.lbGia.setText(txtGia);
    this.giap= Integer.parseInt(txtGia);
    }
      
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        txtslg = new javax.swing.JTextField();
        txtDonvi = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        txtCMT = new javax.swing.JLabel();
        txtma = new javax.swing.JLabel();
        txtNgay = new javax.swing.JLabel();
        txtTT = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        lbGia = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        bttTT = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("CMT:");

        jLabel3.setText("Phòng:");

        jLabel4.setText("Thanh toán cho:");

        jLabel5.setText("Thành tiền:");

        txtslg.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtslgActionPerformed(evt);
            }
        });

        txtDonvi.setText("Tháng");

        jLabel8.setText("Ngày:");

        txtCMT.setText("jLabel9");

        txtma.setText("jLabel2");

        txtNgay.setText("jLabel2");

        jLabel2.setText("Giá:");

        lbGia.setText("jLabel7");

        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel7.setText("Thanh toán tiền phòng");

        bttTT.setText("Thanh toán");
        bttTT.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bttTTActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(48, 48, 48)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(5, 5, 5)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel8)
                                    .addComponent(jLabel3)
                                    .addComponent(jLabel2))
                                .addGap(63, 63, 63)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lbGia)
                                    .addComponent(txtma, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(txtNgay, javax.swing.GroupLayout.DEFAULT_SIZE, 125, Short.MAX_VALUE)
                                    .addComponent(txtCMT, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel4)
                                    .addComponent(jLabel5))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(txtTT, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(txtslg, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18)
                                .addComponent(txtDonvi)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel6))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(97, 97, 97)
                        .addComponent(bttTT)))
                .addContainerGap(118, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(101, 101, 101)
                .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, 232, Short.MAX_VALUE)
                .addGap(66, 66, 66))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addComponent(jLabel7)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(110, 110, 110)
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 157, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(txtCMT))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtma)
                            .addComponent(jLabel3))
                        .addGap(14, 14, 14)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel8)
                            .addComponent(txtNgay))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(lbGia))
                        .addGap(27, 27, 27)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtslg, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtDonvi))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(txtTT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(34, 34, 34)))
                .addComponent(bttTT)
                .addGap(33, 33, 33))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void txtslgActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtslgActionPerformed
    String sl= txtslg.getText().toString();
    int slg= Integer.parseInt(sl);
    if("Tháng".equals(txtDonvi.getText())){
    this.tienTT= giap*slg;
    }
    else
    if("Quý".equals(txtDonvi.getText())){
     this.tienTT= giap*slg*3;   
    }
    else{
      this.tienTT= giap*slg*12;
    }
    this.txtTT.setText(this.tienTT+"");
    this.bttTT.requestFocus();
}//GEN-LAST:event_txtslgActionPerformed

private void bttTTActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bttTTActionPerformed
        Thanhtoan tt=new Thanhtoan();
        tt.setCmt(Integer.parseInt(this.txtCMT.getText().toString()));
        tt.setMaPhong(Integer.parseInt(this.txtma.getText().toString()));
        tt.setNgayTT(this.ngaytt);
        tt.setSoTien(this.tienTT);
        boolean result = false;
        try {
            result = ThanhToanBLL.insertTT(tt);
        } catch (Exception ex) {
            Logger.getLogger(TToan.class.getName()).log(Level.SEVERE, null, ex);
        }
        if (result) {
            try {
                JOptionPane.showMessageDialog(this, "Thanh toán thành công");
                this.dispose();
                CSKhachHang cs=new CSKhachHang();
                cs.show();
            } catch (Exception ex) {
                Logger.getLogger(TToan.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        else {
            JOptionPane.showMessageDialog(this, "Lỗi");
        }
        
}//GEN-LAST:event_bttTTActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(TToan.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(TToan.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(TToan.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(TToan.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
       
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bttTT;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel lbGia;
    private javax.swing.JLabel txtCMT;
    private javax.swing.JLabel txtDonvi;
    private javax.swing.JLabel txtNgay;
    private javax.swing.JTextField txtTT;
    private javax.swing.JLabel txtma;
    private javax.swing.JTextField txtslg;
    // End of variables declaration//GEN-END:variables
}
